package com.nmcc.app_adherence;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;

import android.os.Environment;
import android.widget.Toast;
import android.content.Context;

public class ReadCSV {
 
  public void run(Context context) {
 
	
	String sdcard = Environment.getExternalStorageDirectory().toString();
	//String csvFile = "/Users/mkyong/Downloads/GeoIPCountryWhois.csv";
	//sdcard+ "/bluetooth/" + CSVfilenameGPS
	//InputStream is = getAssets().open("drop down lists for travel questions.csv")
	String csvFile = sdcard + "/districts.csv";
	
	BufferedReader br = null;
	String line = "";
	String cvsSplitBy = ",";
 
	try {
 
		br = new BufferedReader(new FileReader(csvFile));
		while ((line = br.readLine()) != null) {
 
		        // use comma as separator
			String[] country = line.split(cvsSplitBy);
 
			//System.out.println("Country [code= " + country[4] 
                              //   + " , name=" + country[5] + "]");
			
			String s="Country [code= " + country[1] 
                    + " , name=" + country[2] + "]";
			
			Toast.makeText(context, s, Toast.LENGTH_LONG).show();

		}
 
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		if (br != null) {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
 
	System.out.println("Done");
  }
 
}